import Vue from "vue";
import Router from "vue-router";
import Home from "@/components/Home";
import Cart from "@/components/Cart";
import Orders from "@/components/Orders";
import Payments from "@/components/Payments";
// 导入登录页面组件
import Login from "@/views/login.vue";
import login2 from "@/views/login2.vue";

import Control from "@/views/Control.vue";
import Profile from "@/views/profile.vue";
import Businessman_home from "@/views/Businessman_home.vue";

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: "/",
      component: Home,
    },
    // 添加登录页面路由
    {
      path: "/login",
      name: "Login",
      component: Login,
    },
    { path: "/cart", component: Cart },
    { path: "/orders", component: Orders },
    { path: "/payments", component: Payments },
    { path: "/control", component: Control },
    { path: "/profile", component: Profile },
    { path: "/businessman_home", component: Businessman_home },
    { path: "/login2", component: login2 },
  ],
});

// 添加全局导航守卫
router.beforeEach((to, from, next) => {
  // 如果要去登录或商家管理页面，允许访问
  if (to.path === "/login2" || to.path === "/control" || to.path === "/login") {
    next();
  } else {
    // 否则，允许访问其他页面
    next();
  }
});

export default router;
